<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<HTML>
<HEAD>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%--<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />--%>
    <LINK href="${pageContext.request.contextPath}/css/Style1.css" type="text/css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.4.min.js"
            type="text/javascript"></script>
</HEAD>

<body>
<!--  -->
<form action="${pageContext.request.contextPath}/admin/adminProductAdd.do" id="uploadfrom"
      method="post" enctype="multipart/form-data">
    &nbsp;
    <table cellSpacing="1" cellPadding="5" width="100%" align="center" bgColor="#eeeeee"
           style="border: 1px solid #8ba7e3" border="0">
        <tr>
            <td class="ta_01" align="center" bgColor="#afd1f3" colSpan="4"
                height="26">
                <strong><STRONG>添加商品</STRONG>
                </strong>
            </td>
        </tr>

        <tr>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                商品名称：
            </td>
            <td class="ta_01" bgColor="#ffffff">
                <input type="text" name="name" value="" class="bg"/>
            </td>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                是否热门：
            </td>
            <td class="ta_01" bgColor="#ffffff">
                <select id="isHot" name="isHot">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </td>
        </tr>
        <tr>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                市场价格：
            </td>
            <td class="ta_01" bgColor="#ffffff">
                <input type="text" name="marketPrice" value=""
                       class="bg"/>
            </td>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                商城价格：
            </td>
            <td class="ta_01" bgColor="#ffffff">
                <input type="text" name="shopPrice" value=""
                       class="bg"/>
            </td>
        </tr>
        <tr>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                商品图片：
            </td>

            <td class="ta_01" bgColor="#ffffff" colspan="3">
                <img style="width: 100px;height: 100px;" id="selImg" class="img" name="img" src="" alt="">
                <input type="file" id="photo" name="upload"/>
                <span id="uploadInfo"></span>
            </td>
        </tr>
        <tr>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                所属分类：
            </td>
            <td class="ta_01" bgColor="#ffffff" colspan="3">
                <select id="cid" name="cid">
                    <c:forEach items="${list}" var="list">
                        <option value="${list.cid}">${list.cname}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                商品描述：
            </td>
            <td class="ta_01" bgColor="#ffffff" colspan="3">
                <textarea id="desc" name="desc" rows="5" cols="30"></textarea>
            </td>
        </tr>
        <tr>
            <td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
                库存：
            </td>
            <td class="ta_01" bgColor="#ffffff" colspan="3">
                <input type="text" id="inventory" name="inventory" value=""
                       class="bg"/>
            </td>
        </tr>
        <tr>
            <td class="ta_01" style="WIDTH: 100%" align="center"
                bgColor="#f5fafe" colSpan="4">
                <input type="submit" value="确定"/>

                <FONT face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>
                <INPUT class="" type="button" onclick="history.go(-1)" value="返回"/>
                <span id="Label1"></span>
            </td>
        </tr>
    </table>
</form>
</body>
<script>
    $("input[type='file']").change(function () {
        var file = this.files[0];
        if (window.FileReader) {
            var reader = new FileReader();
            reader.readAsDataURL(file);
            //监听文件读取结束后事件
            reader.onloadend = function (e) {
                $(".img").attr("src", e.target.result);//e.target.result就是最后的路径地址
            };
        }
    });

    //    $("#submit").click = function () {
    //        adminProductadd();
    //    }

    <%--function adminProductadd() {--%>
    <%--$.ajax({--%>
    <%--url: "${pageContext.request.contextPath}/admin/adminProductAdd.do",--%>
    <%--type: "post",--%>
    <%--data: {--%>
    <%--image: $("#photo").val(),--%>
    <%--name: $("input[name='name']").val(),--%>
    <%--isHot: $("#isHot").val(),--%>
    <%--marketPrice: $("input[name='marketPrice']").val(),--%>
    <%--shopPrice: $("input[name='shopPrice']").val(),--%>
    <%--cid: $("#cid").val(),--%>
    <%--desc: $("#desc").val(),--%>
    <%--inventory:$("#inventory").val()--%>
    <%--},--%>
    <%--success: function (d) {--%>
    <%--if (d.msc == 1) {--%>
    <%--location.href = "${pageContext.request.contextPath}/admin/adminFindAllProduct.do?page=0";--%>
    <%--}--%>
    <%--}--%>
    <%--})--%>
    <%--}--%>

</script>
</HTML>